<script setup lang="ts">
import {nextTick, onBeforeUnmount, onMounted, ref} from 'vue'
import keyMaster from 'keymaster'
import {ElMessage} from 'element-plus'

const isRouterAlive = ref(true)

function refreshPage() {
  isRouterAlive.value = false
  nextTick(function () {
    isRouterAlive.value = true
  })
}

onMounted(() => {
  keyMaster('f5', function () {
    refreshPage()
    ElMessage('refresh')
    return false
  })
})

onBeforeUnmount(() => {
  keyMaster.unbind('f5')
})
</script>

<template>
  <router-view v-if="isRouterAlive"/>
</template>
